import Vue from 'vue'

export function range(n){
  let out = []
  for(let i = 0; i < n; i++){
    out.push(i)
  }
  return out
}

export function sleep(t){
  return new Promise(r => setTimeout(r, t))
}

export function nextFrame(){
  return new Promise(r => requestAnimationFrame(r))
}

export function nextTick(){
  return new Promise(r => Vue.nextTick(r))
}
export function  throttle(delay, action){
    let last = 0
    return function() {
      let curr = +new Date()
      if(curr - last > delay) {
        action.apply(this, arguments)
        last = curr
      }
    }
  }
export  function debounce(idle, action){
		let last
		return function(){
		let ctx = this
		let args = arguments
		clearTimeout(last)
		last = setTimeout(function(){
			action.apply(ctx, args)
		}, idle)
  0}
}

export  function limitText(arr, vue){
  function cb(value){
    return value.length <= 35
  }
  let flag = arr.every(cb)
  if(flag == false){
      vue.$message.error('每个关键词限制在三十五以内')
      return false
  }
    else
      return true
}


